import { createRouter, createWebHistory } from 'vue-router';
import { useRoleStore } from '@/stores/role';
import HomeView from '../components/HomeView.vue';
import ChatView from '../components/ChatView.vue';
import CallView from '../components/CallView.vue'; // 新增电话聊天界面

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView
    },
    {
      path: '/chat/:roleId',
      name: 'chat',
      component: ChatView,
      props: true,
      beforeEnter: (to) => {
        const roleStore = useRoleStore();
        if (!roleStore.getRoleById(to.params.roleId as string)) {
          return { name: 'home' };
        }
      }
    },
    {
      path: '/call',
      name: 'call',
      component: CallView,
      props: route => ({
        roleId: route.query.roleId,
        roleName: route.query.roleName,
        roleAvatar: route.query.roleAvatar,
        roleDescription: route.query.roleDescription,
      })
    }
  ]
});

export default router;
